root_dir="/usr/local/edh"
role=$1
mode=$(cat mode)
master_url=$(cat master)
echo "$(date +"%Y-%m-%d %H:%M:%S") INFO starting $role in $mode mode"
function start_master(){
  $root_dir/spark/sbin/start-master.sh
  start_log_file=$(ls $root_dir/spark/logs | grep .out$ | grep Master)
  cat $root_dir/spark/logs/$start_log_file
}

function start_worker(){
	$root_dir/spark/sbin/start-worker.sh $master_url
	start_log_file=$(ls $root_dir/spark/logs | grep .out$ | grep Worker)
	cat $root_dir/spark/logs/$start_log_file
}

if [ $role == "master" ];then
	start_master
fi

if [ $role == "worker" ];then
	start_worker
fi

if [ $role == "all" ];then
	if [ $mode == "ha" ];then
		echo "$(date +"%Y-%m-%d %H:%M:%S") WARNING parameter all is only supported in sa mode"
		exit 1
	fi
	start_master
	start_worker
fi